﻿using System;
using System.Collections.Generic;
using System.Web;
/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：ContactsTypeAdd.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：通讯录类别的添加与修改
 * 作者：侯建
 * 创建日期：2011.04.08
************************************************/
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.DBUtility;
using System.Data.SqlClient;

namespace Jxym.wlkc2011.Module.Default.server.Contacts
{
    public partial class ContactsTypeAdd : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int modelid = 0;
                if (Request.Params["modelid"] != null) modelid = Convert.ToInt32(Request.Params["modelid"]);
                string returnValue = "{success:false,msg:'参数不正确'}";
                try
                {
                    if (Request.Params["CommunityClasstext"] != null)
                    {
                        string text = Request.Params["CommunityClasstext"];

                        MsSqlDal<ContactsType> iUc = new MsSqlDal<ContactsType>();
                        SqlParameter[] parameters = new SqlParameter[] 
                        {
                            new SqlParameter("@ContactsTypeName", text),
                            new SqlParameter("@AddUser",Jxym.Common.Request.AdminID("user"))
                        };


                        if (Request.Params["CommunityClassid"] != null)
                        {
                            int id = Convert.ToInt32(Request.Params["CommunityClassid"]);
                            model.ContactsType communityclassmodel = iUc.GetModel("ContactsTypeID = " + id, null);
                            //判断该通知发布人是不是当前用户 和 当前用户权限
                            if (MyGet.GetPermissionsValidation(modelid, "U", Jxym.Common.Request.AdminID("user")) && Jxym.Common.Request.AdminID("user").Equals(communityclassmodel.AddUser.ToString()))
                            {
                                iUc.Updata("ContactsTypeID =" + Convert.ToInt32(Request.Params["CommunityClassid"]), parameters);
                                returnValue = "{'success':true,'msg':'更新完成'}";
                            }
                            else
                            {
                                returnValue = "{'success':false,'msg':'对不起，您没有编辑权限'}";
                            }
                        }
                        else
                        {
                            if (MyGet.GetPermissionsValidation(modelid, "D", Jxym.Common.Request.AdminID("user")))
                            {
                                iUc.Add(parameters);
                                returnValue = "{'success':true,'msg':'添加完成'}";
                            }
                            else
                            {
                                returnValue = "{'success':false,'msg':'对不起，您没有添加权限'}";
                            }
                        }
                    }
                    Response.Write(returnValue);
                }
                catch
                {
                    Response.Write("{success:false,msg:'参数不正确'}");
                }
            }
        }
    }
}